package org.gitos.cloud.server.rpc;

import java.sql.Date;

import org.gitos.cloud.domain.rpc.BLoginRpc;
import org.gitos.cloud.domain.server.Admin;
import org.gitos.cloud.server.service.AdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;

@Service
public class BLoginRpcImp extends CommonMethod implements BLoginRpc {

	private static Logger log = LoggerFactory.getLogger(BLoginRpcImp.class);

	@Autowired
	private AdminService adminService;

	@Override
	public Admin get(String username) {
		return adminService.get(username);
	}

	@Override
	public void updateLastLoginState(Date datetTime, String ip) {
		adminService.updateLastLoginState(datetTime, ip);
	}

	@Override
	public void updatePassword(String password) {
		adminService.updatePassword(password);
	}

	@Override
	public boolean isPasswordEqual(String username, String password) {
		Admin admin = adminService.get(username);
		if (admin == null) {
			return false;
		}
		return  adminService.isPasswordEqual(password, admin.getSalt(), admin.getPassword());
	}
}
